﻿using B.S.DataBase.MyProject.Domain.RBAC;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.RoleCommand;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.RoleCommandHandler
{
    public class GetRoleAllCommandHandler : IRequestHandler<GetRoleAllCommand, APIResult<List<Role>>>
    {

        private readonly IBaseRepository<Role> roleRele;

        public GetRoleAllCommandHandler(IBaseRepository<Role> roleRele)
        {
            this.roleRele = roleRele;
        }

        public Task<APIResult<List<Role>>> Handle(GetRoleAllCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Role>> result = new APIResult<List<Role>>();
            var list = roleRele.GetAll().Result.Where(x => x.IsDeleted == false);
            if (list == null)
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            else
            {
                result.Code = APIEnum.成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data=list.ToList();

            }
            return Task.FromResult(result);
        }
    }
}
